package com.NewsServlet;

import com.NewsService.NewsService;
import com.NewsServiceImpl.NewsServiceImpl;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class News2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        System.out.println("-------servlet");
        String name =  req.getParameter("name");
        String newsid = req.getParameter("newsid");
        if (newsid != null || newsid != "") {
            int newId = Integer.parseInt(newsid);
            NewsService newsService = new NewsServiceImpl();
            int count = newsService.ServiceSdeleteById(newId);
            if (count > 0) {
                resp.sendRedirect(req.getContextPath() + "/index.jsp");
            } else {
                System.out.println("这是get请求");
            }
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("这是post请求");
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
        System.out.println("servlet初始化，init被调用！");
        String initParam = config.getInitParameter("charSetContent");
        System.out.println("initParam---> " + initParam);
    }

}
